using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "new dialogue",menuName = "Dialogue/Dialogue Data")]
public class DialogueData_SO : ScriptableObject
{
    public List<DialoguePiece> DialogPieces;
    public Dictionary<string, DialoguePiece> DialogueDictionary = new Dictionary<string, DialoguePiece>();
#if UNITY_EDITOR
    private void OnValidate()
    {
        DialogueDictionary.Clear();
        foreach (var piece in DialogPieces)
        {
            if (!DialogueDictionary.ContainsKey(piece.ID))
            {
                DialogueDictionary.Add(piece.ID, piece);
            }
        }
    }
#else
    private void Awake()
    {
        DialogueDictionary.Clear();
        foreach (var piece in DialogPieces)
        {
            if (!DialogueDictionary.ContainsKey(piece.ID))
            {
                DialogueDictionary.Add(piece.ID, piece);
            }
        }
    }
#endif

    public QuestData_SO GetQuest()
    {
        QuestData_SO quest=null;
        foreach (var piece in DialogPieces)
        {
            if (piece.Quest != null)
            {
                quest = piece.Quest;
            }
        }

        return quest; 
    }
}
